package com.bawei.exam57.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.bawei.exam57.base.BaseViewModel
import com.bawei.exam57.entity.GoodEntity
import com.bawei.exam57.entity.HomeEntity
import kotlinx.coroutines.launch
import retrofit2.http.Query

class HomeViewModel: BaseViewModel() {

    val error=MutableLiveData<String>()

    val home=MutableLiveData<HomeEntity>()
    fun getHome(){
        viewModelScope.launch {
            try {
                home.value=api.getHome()
            } catch (e: Exception) {
                error.value=e.message
            }
        }
    }

    val good =MutableLiveData<GoodEntity>()
    fun getGood(limit:Int,page:Int){
        viewModelScope.launch {
            try {
                good.value=api.getGood(limit,page)
            }catch (e:Exception){
                error.value=e.message
            }
        }
    }
}